package com.motu.monstercity.server.game.logic;

import com.motu.monstercity.server.game.userdata.*;
import com.motu.vertx.module.utility.model.EntityManager;
import com.motu.vertx.module.utility.model.Model;
import com.motu.vertx.module.utility.toolset.TimeUtils;
import com.motu.vertx.module.utility.toolset.Tool;

import java.util.ArrayList;
import java.util.List;

public class UnionScuffleUserData extends UnionScuffleBaseData {
    public static UserUnionScuffleWeek getUserUnionScuffle(long userId, long enemyUnionId) {
        Model model = EntityManager.getEntity(UserUnionScuffleWeek.class, userId, enemyUnionId);
        if (model != null) {
            return (UserUnionScuffleWeek) model;
        }
        return null;
    }

    public static List<UserUnionScuffleWeek> getUserUnionScuffleList(long userId) {
        List<UserUnionScuffleWeek> result = new ArrayList<>();
        List<Model> modelList = EntityManager.getEntityList(UserUnionScuffleWeek.class, userId);
        if (modelList.isEmpty()) {
            return result;
        }
        for (Model model : modelList) {
            result.add((UserUnionScuffleWeek) model);
        }
        return result;
    }

    public static List<UserUnionScuffleMatch> getUserUnionScuffleMatchList(long userId) {
        List<UserUnionScuffleMatch> result = new ArrayList<>();
        List<Model> modelList = EntityManager.getEntityList(UserUnionScuffleMatch.class, userId);
        if (modelList.isEmpty()) {
            return result;
        }
        for (Model model : modelList) {
            result.add((UserUnionScuffleMatch) model);
        }
        return result;
    }

    public static UserUnionScuffleMemberWeek getUserUnionScuffleMember(long userId, long enemyUnionId, long memberId) {
        String listKey = EntityManager.getFieldJoinString(userId, enemyUnionId);
        Model model = EntityManager.getEntity(UserUnionScuffleMemberWeek.class, listKey, memberId);
        if (model != null) {
            return (UserUnionScuffleMemberWeek) model;
        }
        return null;
    }

    public static List<UserUnionScuffleMemberWeek> getUserUnionScuffleMemberList(long userId, long enemyUnionId) {
        List<UserUnionScuffleMemberWeek> result = new ArrayList<>();
        String listKey = EntityManager.getFieldJoinString(userId, enemyUnionId);
        List<Model> modelList = EntityManager.getEntityList(UserUnionScuffleMemberWeek.class, listKey);
        if (modelList.isEmpty()) {
            return result;
        }
        for (Model model : modelList) {
            result.add((UserUnionScuffleMemberWeek) model);
        }
        return result;
    }

    public static UserUnionScuffleInfoWeek getUserUnionScuffleInfo(long userId) {
        Model model = EntityManager.getUniqueEntity(UserUnionScuffleInfoWeek.class, userId);
        return (UserUnionScuffleInfoWeek) model;
    }

    public static int getMemberTotalCount(long userId, long enemyUnionId) {
        String listKey = EntityManager.getFieldJoinString(userId, enemyUnionId);
        return (int) EntityManager.getEntityCount(UserUnionScuffleMemberWeek.class, listKey);
    }

    public static List<UnionScuffleNoticeWeek> getUnionScuffleNoticeList() {
        List<UnionScuffleNoticeWeek> result = new ArrayList<>();
        String dayStr = TimeUtils.getDayStr(TimeUtils.getCurTime());
        long day = Long.parseLong(dayStr);
        List<Model> modelList = EntityManager.getEntityList(UnionScuffleNoticeWeek.class, day);
        if (modelList.isEmpty()) {
            return result;
        }
        for (Model model : modelList) {
            result.add((UnionScuffleNoticeWeek) model);
        }
        return result;
    }

    public static List<UnionScuffleReportWeek> getUnionScuffleReportList(long unionId) {
        List<UnionScuffleReportWeek> result = new ArrayList<>();
//        String listKey = EntityManager.getFieldJoinString(unionId, actId);
        List<Model> modelList = EntityManager.getEntityList(UnionScuffleReportWeek.class, unionId);
        if (modelList.isEmpty()) {
            return result;
        }
        for (Model model : modelList) {
            result.add((UnionScuffleReportWeek) model);
        }
        return result;
    }

    public static UserUnionScuffleGiftWeek getUserUnionScuffleGift(long userId, int giftId) {
        Model model = EntityManager.getEntity(UserUnionScuffleGiftWeek.class, userId, giftId);
        if (model != null) {
            return (UserUnionScuffleGiftWeek) model;
        }
        return null;
    }
    public static List<UserUnionScuffleGiftWeek> getUserUnionScuffleGiftList(long userId) {
        List<Model> models = EntityManager.getEntityList(UserUnionScuffleGiftWeek.class, userId);
        List<UserUnionScuffleGiftWeek> result = new ArrayList<>();
        if (!models.isEmpty()) {
            for (Model model : models) {
                result.add((UserUnionScuffleGiftWeek) model);
            }
        }
        return result;
    }

    public static UserUnionScufflePartnerWeek getUserUnionScufflePartner(long userId, long memberId, int partnerId) {
        String listKey = EntityManager.getFieldJoinString(userId, memberId);
        Model model = EntityManager.getEntity(UserUnionScufflePartnerWeek.class, listKey, partnerId);
        if (model != null) {
            return (UserUnionScufflePartnerWeek) model;
        }
        return null;
    }

    public static List<UserUnionScufflePartnerWeek> getUserUnionScufflePartnerList(long userId, long memberId) {
        String listKey = EntityManager.getFieldJoinString(userId, memberId);
        List<Model> models = EntityManager.getEntityList(UserUnionScufflePartnerWeek.class, listKey);
        List<UserUnionScufflePartnerWeek> result = new ArrayList<>();
        if (!models.isEmpty()) {
            for (Model model : models) {
                result.add((UserUnionScufflePartnerWeek) model);
            }
        }
        return result;
    }

    public static List<UserUnionScuffleShopWeek> getUserUnionScuffleShopList(long userId) {
        List<Model> models = EntityManager.getEntityList(UserUnionScuffleShopWeek.class, userId);
        List<UserUnionScuffleShopWeek> result = new ArrayList<>();
        if (!models.isEmpty()) {
            for (Model model : models) {
                result.add((UserUnionScuffleShopWeek) model);
            }
        }
        return result;
    }

    public static UserUnionScuffleShopWeek getUserUnionScuffleShop(long userId, int shopId) {
        Model model = EntityManager.getEntity(UserUnionScuffleShopWeek.class, userId, shopId);
        if (model != null) {
            return (UserUnionScuffleShopWeek) model;
        }
        return null;
    }

}
